<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户登录</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>

<div id="app">

    <el-form :inline="true" class="demo-form-inline">
        <el-form-item label="用户名">
            <el-input v-model="user.username" placeholder="用户名"></el-input>
        </el-form-item>
        <el-form-item label="密码">
            <el-input type="password" v-model="user.password" placeholder="密码"></el-input>
        </el-form-item>

        <el-form-item>
            <el-button type="primary" @click="onSubmit">登录</el-button>
        </el-form-item>
    </el-form>
</div>


<script>
    axios.defaults.withCredentials=true;
    new Vue({
        el: "#app",
        data() {
            return {
                user: {
                    username: '',
                    password: ''
                }
            }
        },
        methods:{
            onSubmit:function(){
                let _this = this;
                // 为给定 ID 的 user 创建请求
                axios.get('http://localhost:8090/car-recommand/api/user/login?username='
                    +this.user.username+"&password="+this.user.password)
                    .then(function (response) {
                        console.log(response.data.results);
                        localStorage.setItem("user",response.data.results)

                    })
                    .catch(function (error) {
                        console.log(error);
                    });
            }
        }
    });
</script>

</body>
</html>